package net.simflow.swf.analyzer.exec.stats.opt;

import java.util.ArrayList;
import java.util.Map.Entry;
import java.util.TreeMap;

import net.simflow.swf.analyzer.exec.data.TaskExecResult;

public class ExecTimeDistributionAnalyzer {

	private static ExecTimeDistributionAnalyzer instance = new ExecTimeDistributionAnalyzer();

	private ExecTimeDistributionAnalyzer() {
	}

	public static ExecTimeDistributionAnalyzer getInstance() {
		return instance;
	}

	public TreeMap<Integer, ArrayList<TaskExecResult>> analyze(
			TreeMap<Integer, TaskExecResult> taskExecMap) {
		TreeMap<Integer, ArrayList<TaskExecResult>> map = new TreeMap<Integer, ArrayList<TaskExecResult>>();

		if (taskExecMap == null) {
			return map;
		}

		for (Entry<Integer, TaskExecResult> en : taskExecMap.entrySet()) {
			TaskExecResult tr = en.getValue();
			int execT = tr.getExecTime();
			ArrayList<TaskExecResult> a = map.get(execT);
			if (a == null) {
				a = new ArrayList<TaskExecResult>();
				map.put(execT, a);
			}
			a.add(tr);
		}
		map.comparator();

		return map;
	}
}
